package cn.itcast.search.controller;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class SearchController {
    @Autowired
    SearchService searchService;

    @PostMapping("list")
    public PageDTO<ItemDoc> find(@RequestBody SearchReqDTO searchReqDTO) throws IOException {
        return searchService.find(searchReqDTO);
    }
    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody SearchReqDTO searchReqDTO) throws IOException {
        return searchService.getFilters(searchReqDTO);
    }
    @GetMapping("suggestion")
    public List<String> suggestion(@RequestParam String key){
        return searchService.suggestion(key);
    }
}
